<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>控制台-品牌管理-浙江星全汽车服务有限公司</title>
		<meta name="keywords" content="控制台" />
		<meta name="description" content="控制台" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />

		<!-- basic styles -->

		<link href="/public/static/admin/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="/public/static/admin/css/font-awesome.min.css" />

		<!--[if IE 7]>
		  <link rel="stylesheet" href="/public/static/admin/css/font-awesome-ie7.min.css" />
		<![endif]-->

		<!-- page specific plugin styles -->

		<link rel="stylesheet" href="/public/static/admin/css/ace.min.css" />
		<link rel="stylesheet" href="/public/static/admin/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="/public/static/admin/css/ace-skins.min.css" />

		<!--[if lte IE 8]>
		  <link rel="stylesheet" href="/public/static/admin/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->

		<script src="/public/static/admin/js/ace-extra.min.js"></script>
		<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

		<!--[if lt IE 9]>
		<script src="/public/static/admin/js/html5shiv.js"></script>
		<script src="/public/static/admin/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body>
		<div class="navbar navbar-default" id="navbar">
			<script type="text/javascript">
				try{ace.settings.check('navbar' , 'fixed')}catch(e){}
			</script>

			<div class="navbar-container" id="navbar-container">
				<div class="navbar-header pull-left">
					<a class="navbar-brand">
						<small>
							控制台-浙江星全汽车服务有限公司
						</small>
					</a><!-- /.brand -->
				</div><!-- /.navbar-header -->
				<div class="navbar-header pull-right">
					<button type="button" id="logOut" class="btn btn-sm btn-danger" data-toggle="button" style="margin-top:5px;">退出</button>
				</div>
			</div><!-- /.container -->
		</div>

		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<div class="main-container-inner">
				<a class="menu-toggler" id="menu-toggler" href="#">
					<span class="menu-text"></span>
				</a>

				<div class="sidebar" id="sidebar">
					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'fixed')}catch(e){}
					</script>

					<ul class="nav nav-list">
						<li class="active">
							<a href="/admin/index/brand">
								<i class="icon-list-alt"></i>
								<span class="menu-text"> 品牌管理 </span>
							</a>
						</li>

						<li>
							<a href="/admin/index/product">
								<i class="icon-list"></i>
								<span class="menu-text"> 产品管理 </span>
							</a>
						</li>
						<li>
							<a href="/admin/index/intention">
								<i class="icon-edit"></i>
								<span class="menu-text"> 购车意向 </span>
							</a>
						</li>
					</ul><!-- /.nav-list -->

					<div class="sidebar-collapse" id="sidebar-collapse">
						<i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i>
					</div>

					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'collapsed')}catch(e){}
					</script>
				</div>

				<div class="main-content">
					<div class="page-content">
						<div class="page-header">
							<h1>
								品牌管理
							</h1>
							
						</div>
						<div class="navbar pull-left">

						</div>
						<div class="navbar pull-right">
							<button id="addBrand" class="btn btn-info">品牌添加</button>
						</div>
						
						<div class="row">
							<div class="col-xs-12">
								<div class="table-responsive">
									<table id="sample-table-2" class="table table-striped table-bordered table-hover">
										<thead>
											<tr>
												<th>品牌名称</th>
												<th>品牌图片</th>
												<th>操作</th>
											</tr>
										</thead>

										<tbody>
											<?php
												if ($list != null && isset($list['list']) && $list['list'] != null && is_array($list['list']) && count($list['list']) > 0) {
													foreach ($list['list'] as $value) {
														echo "<tr>";
														echo "<td>".$value['name']."</td>";
														echo "<td><img src='/public/uploads/".$value['url']."' style='width:23px;height:23px'></td>";
														echo "<td>";
														echo '<div class="action-buttons">';
														echo '<a class="red" onclick="delBrand('.$value["id"].')"><i class="icon-trash bigger-130"></i></a>';
														echo "</div>";
														echo "</td>";
														echo "</tr>";
													}
												}

											?>	
										</tbody>
									</table>
								</div>
							</div>
						</div>

						<div class="row">
							<div class="col-sm-6">
								<div class="dataTables_info" id="sample-table-2_info">Showing<?php echo $list['pageStart']." to ". $list['pageEnd'] ." of ". $list["count"]; ?> entries</div>
							</div>
							<div class="col-sm-6">
								<div class="dataTables_paginate paging_bootstrap">
									<ul class="pagination">
										<li <?php if($list['firstPage'] == $list['thisPage']) {
												echo 'class="prev disabled"';
											} ?>>
											<a href="/admin/index/brand?page=1" data-page="<?php echo $list['firstPage']?>"><i class="icon-double-angle-left"></i></a>
										</li>
										<?php 
											if (isset($list['pageList']) && is_array($list['pageList']) && count($list['pageList']) > 0) {
												foreach ($list['pageList'] as $pageList) {
													if ($pageList > 0 ) {
														if ($pageList == $list['getPage']) {
														echo "<li class=\"active\"><a href=\"/admin/index/brand?page=".$pageList."\" data-page='".$pageList."'>".$pageList."</a>";
														} else {
															echo "<li><a href=\"/admin/index/brand?page=".$pageList."\" data-page='".$pageList."'>".$pageList."</a>";
														}
													}
												}
											}

										?>
										
										<li <?php if($list['lastPage'] == $list['thisPage']) {
												echo 'class="prev disabled"';
											} ?>>
											<a href="<?php echo '/admin/index/brand?page='.$list['lastPage'] ?>" data-page="<?php echo $list['lastPage']?>"><i class="icon-double-angle-right"></i></a>
										</li>
									</ul>
								</div>
							</div>
						</div>
					</div><!-- /.page-content -->
				</div><!-- /.main-content -->
			</div><!-- /.main-container-inner -->
		</div><!-- /.main-container -->

		<div class="bootbox modal fade in" id="addBrandInfo" tabindex="-1" role="dialog" aria-hidden="false" style="display:none;">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">  
			      		<button type="button" class="bootbox-close-button close closeAddBrandInfo" style="margin-top: -10px;">×</button>
						<div class="bootbox-body">
			      			<h4 class="modal-title">添加品牌</h4>  
			    		</div> 
			    	</div>
			    	<form id="imageForm" enctype="multipart/form-data">
						<div class="modal-body" style="height:150px;">
							<div class="form-group">
								<label class="col-sm-3 control-label"> 品牌名称 *</label>
								<div class="col-sm-9">
									<input type="text" id="brandName" placeholder="品牌名称" class="col-xs-9">
								</div>
							</div>
							<br/>
							<div class="form-group">
								<label class="col-sm-3 control-label"> 品牌图片 *</label>
								<div class="col-sm-9">
									<input type="file" id="img" name="img" value="">
								</div>
							</div>
						</div>
					</form>
					<div class="modal-footer">
						<button id="addBrandInfoButton" type="button" class="btn btn-sm btn-success">
							<i class="icon-ok"></i>保存
						</button>
						<button data-bb-handler="button" type="button" class="btn btn-sm closeAddBrandInfo">取消
						</button>
					</div>
				</div>
			</div>
		</div>
		<!-- basic scripts -->
		<!--[if !IE]> -->

		<script type="text/javascript">
			window.jQuery || document.write("<script src='/public/static/admin/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='/public/static/admin/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
</script>
<![endif]-->

		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='/public/static/admin/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="/public/static/admin/js/bootstrap.min.js"></script>
		<script src="/public/static/admin/js/typeahead-bs2.min.js"></script>

		<!-- page specific plugin scripts -->

		<!-- ace scripts -->

		<script src="/public/static/admin/js/ace-elements.min.js"></script>
		<script src="/public/static/admin/js/ace.min.js"></script>
		<div class="bg-warper" style="display: none;z-index: 9999;opacity: .7;width: 100%;height: 100%;position: fixed;top: 0;left: 0;background-color: #000;"></div>
</body>
</html>

<script src="/public/static/admin/js/jquery.form.js"></script>
<script type="text/javascript">
$("#logOut").click(function(){
    $.ajax({
        type: "POST",
        url: "/admin/index/logOut",
        dataType: "json",
        success: function(data){
            if (data['code'] == 0) {
                alert(data['msg']);
            } else {
                window.location = data['url'];
            }
        }
    });
});

$("#addBrand").on("click", function() {
	$("#addBrandInfo").css("display","block");
});

$(".closeAddBrandInfo").click(function() {
	$("#addBrandInfo").css("display","none");
});

$("#addBrandInfoButton").click(function() {
	var brandName = $("#brandName").val();
	var img = $("#img").val();

	if (brandName == null || brandName == undefined || brandName.length <= 0) {
		alert("品牌名称不允许为空！");
		return;
	}

	if (img == null || img == undefined || img.length <= 0) {
		alert("品牌图片不允许为空！");
		return;
	}
	$(".bg-warper").css("display","block");
	var params = {
        url: "/admin/index/addBrand",
        type:"POST",
        dataType:"json",
        data:{
        	"brandName":brandName,
        	"img":img
        },
        clearFomr: true,
        resetFomr: true,
        timeout: 3000,
        success:function(responseText,statusText,xhr,$form){
        	$(".bg-warper").css("display","none");
            if (responseText['code'] == 0) {
                alert(responseText['msg']);
            } else {
                location.reload();
            }
        },
        beforeSubmit: function(formData, jqForm, options){
        	if((formData[0]['value']['type']).indexOf("image/")==-1){  
				alert("图片类型有误!");  
				return false;
			}  
			var fileName = formData[0]['value']['name'];  
			var suffixIndex = fileName.lastIndexOf(".");  
			var suffix = fileName.substring(suffixIndex+1).toUpperCase();  
			if (suffix != "JPG" && suffix != "JPEG" && suffix != "PNG" && suffix != "GIF"){  
				alert("图片类型有误!格式JPG、JPEG、PNG、GIF");  
				return false;
			}  
        }
    };
	$("#imageForm").ajaxSubmit(params);
	return false;
});
function delBrand(id) {
	$.ajax({
        type: "POST",
        url: "/admin/index/delBrand",
        dataType: "json",
        data:{"id":id},
        success: function(data){
            if (data['code'] == 0) {
                alert(data['msg']);
            } else {
                window.location = data['url'];
            }
        }
    });
}
</script>